#!/bin/sh
#if the pkg created in packages-woof has something wrong, this file is a last
#resort to fix it. Current-dir is where this file FIXUPHACK is located.

# Xorg/X is in xserver-xorg..
rm -f usr/bin/X

#slackware: /etc/X11/xkb
#debian   : /usr/share/X11/xkb

#slackware: usr/share/X11/xkb/ is already a symlink..
#           created by the slackware post-install script (most likely)
if [ ! -L usr/share/X11/xkb ] ; then
	#debian
	mv -f usr/share/X11/xkb/* etc/X11/xkb/ 2>/dev/null
	rm -rf usr/share/X11/xkb/
	ln -sv ../../../etc/X11/xkb usr/share/X11/xkb
fi

# http://packages.slackware.com/?r=slackware-14.2&p=libX11-1.6.4-i586-1_slack14.2.txz&f
# http://packages.ubuntu.com/xenial/libx11-data -> http://packages.ubuntu.com/xenial/all/libx11-data/filelist
# slackware: libX11
# debian:    libX11-data
# keep: C en_US.UTF-8 iso8859-1 iso8859-2 iso8859-15 [following old template]
# pkg template should not have 'nls>null'. Have to copy stuff from NLS dir.
#   ,nls     is the preferred option
#   ,nls>exe is acceptable
if [ -d ../xorg_base_new_NLS ] ; then
	mkdir -p usr/share/X11/locale/
	cp -af ../xorg_base_new_NLS/usr/share/X11/locale/* usr/share/X11/locale/
else
	if [ ! -d usr/share/X11/locale/C ] ; then
		echo '!!! ERROR: ../xorg_base_new_NLS MISSING !!!'
	fi
fi
find usr/share/X11/locale  -mindepth 1 -maxdepth 1 -type d | \
	grep -Ev '/C$|/en_US.UTF-8$|/iso8859-1$|/iso8859-2$|/iso8859-15$' | \
		while read dir ; do
			rm -rf "$dir"
		done

#100416 ubuntu lucid has moved libGL.so* to /usr/lib/mesa (why oh why!!!???)...
#note, but not libGLU.so*
if [ -e usr/lib/mesa/libGL.so.1 ];then
 ln -s mesa/libGL.so.1 usr/lib/libGL.so.1
 ln -s mesa/libGL.so usr/lib/libGL.so
 ln -s mesa/libGL.so.1.2 usr/lib/libGL.so.1.2
fi

#120406 gxmessage pkg creates xmessage symlink to it (in pinstall.sh). get real xmessage out of the way...
if [ -f usr/bin/xmessage ];then
 if [ ! -h usr/bin/xmessage  ];then
  mkdir -p usr/local/bin
  mv -f usr/bin/xmessage usr/local/bin/
 fi
fi

#===================================

cp --remove-destination -r z/* .
rm -rf z/

#if /etc/fonts/fonts.conf is not present, use traditional Puppy-style font settings
if [ -f etc/fonts/fonts.conf ];then
 rm -rf etc/fonts-puppy
else
 rm -rf etc/fonts
 mv etc/fonts-puppy etc/fonts
fi

if [ -d usr/lib ] ; then
	mv usr/xserver usr/lib/
fi

ln -sv ../../../etc/X11/app-defaults usr/share/X11/app-defaults
rm -rf etc/X11/xinit

mkdir -p var/cache/fontconfig
mkdir -p var/lib/xkb

# Bitmaps that are shared between X applications are in an odd place..
if [ -d ../xorg_base_new_DEV/usr/include/X11/bitmaps ] ; then
	mkdir -p usr/include/X11/
	mv -f ../xorg_base_new_DEV/usr/include/X11/bitmaps usr/include/X11/
fi
